MINIFICPP-2798 Mock library for C extensions#2170
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a C++ mock library intended to support testing/verification of C extensions, and refactors the C++ extension wrapper layer to rely on abstract ProcessContext / ProcessSession interfaces with concrete CFFI-backed implementations.
Changes:
- Refactor extension wrapper APIs (
ProcessContext,ProcessSession,Logger) to use abstract base classes and CFFI-backed concrete implementations (Cffi*). - Add a new
mocklib(mock process context/session/logger + stubbed C API symbols) for extension testing without a full agent runtime. - Extend/adjust C API utility helpers (
minifiStringView, conversions) and add new small common utilities (regex wrapper + attribute error category).
Reviewed changes
Copilot reviewed 24 out of 28 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| libminifi/test/integration/extension-verification-test/CApiExtension.cpp | Updates extension metadata string-view helper usage. |
| extensions/llamacpp/processors/RunLlamaCppInference.cpp | Adjusts property access to updated ProcessContext API. |
| extensions/llamacpp/processors/ExtensionInitializer.cpp | Updates extension metadata string-view helper usage. |
| extension-framework/cpp-extension-lib/src/core/ProcessSession.cpp | Implements CFFI-backed ProcessSession operations + new session APIs. |
| extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp | Implements CFFI-backed ProcessContext operations + dynamic props/SSL data. |
| extension-framework/cpp-extension-lib/src/core/logging/Logger.cpp | Renames/implements CFFI-backed logger wrapper. |
| extension-framework/cpp-extension-lib/src/core/ControllerServiceContext.cpp | Updates controller service property lookup string-view helper usage. |
| extension-framework/cpp-extension-lib/mocklib/src/MockProcessSession.cpp | Adds mock session implementation for tests (flow file lifecycle, content, attributes). |
| extension-framework/cpp-extension-lib/mocklib/src/MockProcessContext.cpp | Adds mock context implementation for tests (properties, defaults). |
| extension-framework/cpp-extension-lib/mocklib/src/mock-minifi-c.cpp | Adds stubbed C API symbol definitions for mock/test linkage. |
| extension-framework/cpp-extension-lib/mocklib/include/MockUtils.h | Adds small helpers for building mock processor metadata/logger. |
| extension-framework/cpp-extension-lib/mocklib/include/MockStreams.h | Adds in-memory mock InputStream/OutputStream implementations. |
| extension-framework/cpp-extension-lib/mocklib/include/MockProcessSession.h | Declares mock session class and mock flow file data model. |
| extension-framework/cpp-extension-lib/mocklib/include/MockProcessContext.h | Declares mock process context class. |
| extension-framework/cpp-extension-lib/mocklib/include/MockLogger.h | Adds a test logger capturing log strings by level. |
| extension-framework/cpp-extension-lib/mocklib/CMakeLists.txt | Adds build target for the new mock library. |
| extension-framework/cpp-extension-lib/include/api/utils/Ssl.h | Introduces SSL data structs for the extension API surface. |
| extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h | Updates property parsing helpers to use the new getProperty(PropertyReference, FlowFile*) API. |
| extension-framework/cpp-extension-lib/include/api/utils/minifi-c-utils.h | Introduces minifiStringView + adds conversions from MinifiStringView. |
| extension-framework/cpp-extension-lib/include/api/core/Resource.h | Updates registration helpers to use CFFI wrappers + adds variadic registration helpers. |
| extension-framework/cpp-extension-lib/include/api/core/ProcessSession.h | Refactors ProcessSession into abstract interface + adds CffiProcessSession. |
| extension-framework/cpp-extension-lib/include/api/core/ProcessContext.h | Refactors ProcessContext into abstract interface + adds CffiProcessContext and new APIs. |
| extension-framework/cpp-extension-lib/include/api/core/logging/Logger.h | Renames wrapper to CffiLogger. |
| extension-framework/cpp-extension-lib/CMakeLists.txt | Adds mocklib subdirectory to build. |
| core-framework/common/src/utils/RegexUtils.cpp | Adds regex implementation backing new RegexUtils header. |
| core-framework/common/src/utils/AttributeErrors.cpp | Adds attribute error category implementation. |
| core-framework/common/include/utils/RegexUtils.h | Adds regex wrapper interface and libstdc++ workaround. |
| core-framework/common/include/utils/AttributeErrors.h | Adds attribute error code/category declarations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b89c26e to
a801889
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
a801889 to
6177d0c
Compare
| // api::core::FlowFile requires that somebody takes ownership before it goes out of scope | ||
| // the tested processor should either remove or transfer all FlowFiles it handles | ||
| for (auto& ff : removed_flow_files_) { | ||
| delete ff.release(); // NOLINT(cppcoreguidelines-owning-memory) |
There was a problem hiding this comment.
isn't this the same as ff.reset()?
There was a problem hiding this comment.
No because ff is a
struct EnsureMovedFromDeleter {
void operator()(MinifiFlowFile* ff) {
if (ff) {
throw std::logic_error("Each flowfile should be either transferred or removed");
}
}
};
using FlowFile = std::unique_ptr<MinifiFlowFile, EnsureMovedFromDeleter>;
if we call ff.reset() or simply let the unique_ptr go out of scope the custom deleter will run and throw, with release and delete we skip the custom deleter (which is warranted in this mock environment)
Depends on
Separates the CPP wrapper into a abstract interface and the Cffi layer (that commincates via the stable API), and also introduces a Mock alternative implementation, with its easier to create new unit tests that only test the processors controllers services business logic without the need to depend on the libminifi library.
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically main)?
Is your initial contribution a single, squashed commit?
For code changes:
For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.